/*
 * TransitionNameDialogCommand.java
 *
 * Created on 26 maj 2007, 16:16
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.uj.petri.commands;

import edu.uj.petri.document.Document;
import edu.uj.petri.model.Transition;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;

/**
 *
 * @author Paweł
 */
public class TransitionNameDialogCommand extends Command {
    
    private Transition transition;
    
    /** Creates a new instance of TransitionNameDialogCommand */
    public TransitionNameDialogCommand(Transition transition) {
        super(true); // do not remember on command stack
        this.transition = transition;
    }

    public String toString() {
        
        return ""; // executeAndForget
    }

    void execute() {
        
        String oldName = transition.getName();
        String newName = JOptionPane.showInputDialog( null, ResourceBundle.getBundle("edu/uj/petri/messages").getString("zmiana_nazwy_tranzycji_prompt"), oldName);
        if (newName != null && !newName.equals(""))
        {
          Document.getActiveDocument().execute(new SetTransitionNameCommand( transition, newName ));
        }
    }
    
     void undo() {
        throw new IllegalArgumentException(ResourceBundle.getBundle("edu/uj/petri/messages").getString("cannot_be_undone"));
    }

    boolean canBeCombined(Command c) {
        return false;
    }

    private static final long serialVersionUID = 2747492258596028958L;    
}
